//
//  ToResiduePayViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/26.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "cashierViewController.h"
#import "HAODEsingleton.h"
#import "RDVTabBarController.h"
#import "AttributedLabel.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "ServiceListViewController.h"
#import "orderListsViewController.h"
#import "QRCodeGenerator.h"
#import "UIButton+WebCache.h"
#import "BusinessGatheringViewController.h"
#import "orderListsViewController.h"
#import "BusinessGatheringDetailViewController.h"
#import "UIImage+RTTint.h"
#import "huiyuandengjiViewController.h"

@interface cashierViewController ()<UIScrollViewDelegate,UIGestureRecognizerDelegate>
@property BOOL isUseInEnteringANumber;
@property(nonatomic)NSUInteger orietation;
@property BOOL isContinue;
@property BOOL secondEqual;
@property BOOL firstEqual;

@end
//
@implementation cashierViewController

{
    HAODEsingleton* commdity;
    UILabel*shoukuanfangsi;
    UIButton*xianjinlabelbtn;
    UIButton*shuakabtnlabelbtn;
    UIButton*zhifulabelbaobtn;
    UIButton*weixinbtnlabelbtn;
    UIScrollView*myscrollView;
    UIButton*Btnture;
    NSString *payType;
    AttributedLabel*xuanze;
    UIButton *time;
    NSString*str;
    BOOL isHaveDian;
    UILabel*jiajianhao;
    UILabel*payAmount;
    UIView*ditu;
    UILabel*wufuhaopayAmount;
    UIImageView*chaimageview;
    UIView*addView;
    UIView*View;
    UIView*NOView;
    BOOL saveAccount;
    UIButton*editor1;
    UIButton* backButton;
    UILabel*titleStr;
}


@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    [time removeFromSuperview];
     [self.navigationController popViewControllerAnimated:YES];
 
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=YES;
    [[self rdv_tabBarController] setTabBarHidden:YES];
    saveAccount=YES;
    

    
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
   
    
    [NOView removeFromSuperview];
    
    _narview.backgroundColor=[UIColor colorWithRed:14/255.0 green:23/255.0 blue:0/255.0 alpha:1.0];
    if ([commdity.orderType isEqualToString:@"order"]) {
        [NOView removeFromSuperview];
        NOView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-60)];
        NOView.backgroundColor=[UIColor clearColor];
        [self.view addSubview:NOView];
        
        UILabel*orderNo=[[UILabel alloc]initWithFrame:CGRectMake(0,65+15, ScreenWidth,14)];
        orderNo.textColor=luseColor;
        orderNo.backgroundColor=[UIColor colorWithRed:14/255.0 green:23/255.0 blue:0/255.0 alpha:1.0];
        orderNo.font=[UIFont boldSystemFontOfSize:14];
        [NOView addSubview:orderNo];
        
        if ([commdity.gatheringType isEqualToString:@"N"]) {
            NSString *sat=@"收全款";
            orderNo.text=[NSString stringWithFormat:@"    订单号 %@ %@",  commdity.orderNo,sat];
            
        }
           if ([commdity.gatheringType isEqualToString:@"P"]) {
            NSString *sat=@"收尾款";
            orderNo.text=[NSString stringWithFormat:@"    订单号 %@ %@", commdity.orderNo,sat];
            
        }

    
        NSString*GoldPrice=[NSString stringWithFormat:@"%.2f", commdity.how.doubleValue];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
        
        payAmount.text=[NSString stringWithFormat:@"¥ %.2f", commdity.how.doubleValue];
        payAmount.textAlignment = NSTextAlignmentRight;
        payAmount.textColor=[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0];
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@" ,formattedNumberString]];
        
        [AttributedStr addAttribute:NSFontAttributeName
         
                              value:[UIFont systemFontOfSize:25.0]
         
                              range:NSMakeRange(0, 1)];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0]
         
                              range:NSMakeRange(0, 1)];
        
        
        payAmount.attributedText = AttributedStr;
        wufuhaopayAmount.text=commdity.how;
        
        self.shu.text = @"";
        jiajianhao.text=@"0.00";

  
        
    }
 
    if ([commdity.orderType isEqualToString:@"other"]) {
        [NOView removeFromSuperview];
        NOView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40+65)];
        NOView.backgroundColor=[UIColor clearColor];
        [self.view addSubview:NOView];
        
        UILabel*orderNo=[[UILabel alloc]initWithFrame:CGRectMake(0,65+15, ScreenWidth,16)];
        orderNo.textColor=luseColor;
        orderNo.backgroundColor=[UIColor colorWithRed:14/255.0 green:23/255.0 blue:0/255.0 alpha:1.0];
        orderNo.font=[UIFont boldSystemFontOfSize:14];
        [NOView addSubview:orderNo];
        
       orderNo.text=[NSString stringWithFormat:@"    会员 %@ （%@）",  commdity.userName,commdity.Phone];
 
        
        self.shu.text = @"";
        jiajianhao.text=@"0.00";
       
        
        
    }
    [self jiazaititle];
    
}


-(void)jiazaititle{
    [editor1 removeFromSuperview];
    [backButton removeFromSuperview];
    [titleStr removeFromSuperview];
    UIImage *img=[UIImage imageNamed:@"tianjia"];
    
    UIImage *tinted = [img rt_tintedImageWithColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0] ];
    editor1 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-45, 27.5, 30, 30)];
    [editor1 setImage:tinted forState:UIControlStateNormal];
    [editor1 addTarget:self action:@selector(tianjia:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:editor1];

    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(10,27.5,30,30);
     backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
    
    titleStr=[[UILabel alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 64)];
    titleStr.text=@"收银";
    titleStr.textColor=[UIColor whiteColor];
    titleStr.font=[UIFont systemFontOfSize:18];
    titleStr.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:titleStr];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _isUseInEnteringANumber = YES;
    _isContinue=NO;
    commdity=[HAODEsingleton shared];
    
    [self shouyin];
    
}
- (void)shuzi:(UIButton *)sender
{
    
    if (_isContinue) {
     
        NSString *digit = sender.currentTitle;
        
        if ([sender.titleLabel.text isEqualToString: @"." ]) {
            digit=@"";
        }
        if (_isUseInEnteringANumber){
            
            jiajianhao.text = [self.shu.text stringByAppendingString:digit];
            self.shu.text = [self.shu.text stringByAppendingString:digit];
            NSString*GoldPrice=[NSString stringWithFormat:@"%.2f", self.shu.text.doubleValue];
            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
            [numberFormatter setPositiveFormat:@"###,##0.00;"];
            NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
            
            payAmount.text=[NSString stringWithFormat:@"¥ %.2f", self.shu.text.doubleValue];
            payAmount.textAlignment = NSTextAlignmentRight;
            payAmount.textColor=[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0];
            NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@" ,formattedNumberString]];
            
            [AttributedStr addAttribute:NSFontAttributeName
             
                                  value:[UIFont systemFontOfSize:25.0]
             
                                  range:NSMakeRange(0, 1)];
            
            [AttributedStr addAttribute:NSForegroundColorAttributeName
             
                                  value:[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0]
             
                                  range:NSMakeRange(0, 1)];
            
            
            payAmount.attributedText = AttributedStr;
            wufuhaopayAmount.text=self.shu.text;
        } else {
            
            jiajianhao.text = [jiajianhao.text stringByAppendingString:digit];
            self.shu1.text = [self.shu1.text stringByAppendingString:digit];
        }
        
        
    }else{
        
        
        if ([sender.titleLabel.text isEqualToString: @"." ]) {
            _isContinue=YES;
        }
        
        NSString *digit = sender.currentTitle;
        if (_isUseInEnteringANumber){
           jiajianhao.text = [self.shu.text stringByAppendingString:digit];
            self.shu.text = [self.shu.text stringByAppendingString:digit];
            
           
            
            
            NSString*GoldPrice=[NSString stringWithFormat:@"%.2f", self.shu.text.doubleValue];
            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
            [numberFormatter setPositiveFormat:@"###,##0.00;"];
            NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
            
            payAmount.text=[NSString stringWithFormat:@"¥ %.2f", self.shu.text.doubleValue];
            payAmount.textAlignment = NSTextAlignmentRight;
            payAmount.textColor=[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0];
            NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@" ,formattedNumberString]];
            
            [AttributedStr addAttribute:NSFontAttributeName
             
                                  value:[UIFont systemFontOfSize:25.0]
             
                                  range:NSMakeRange(0, 1)];
            
            [AttributedStr addAttribute:NSForegroundColorAttributeName
             
                                  value:[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0]
             
                                  range:NSMakeRange(0, 1)];
            
            
            payAmount.attributedText = AttributedStr;
            wufuhaopayAmount.text=self.shu.text;
        } else {
            
            jiajianhao.text = [jiajianhao.text stringByAppendingString:digit];
            self.shu1.text = [self.shu1.text stringByAppendingString:digit];
            
        }
    }
    commdity.orderType=@"other";
    commdity.orderId=@"";
//自定义订单号没有情况下；
}
- (void)jiajianfa:(UIButton *)sender {
    
   
    if ([self.shu1 .text length]>0) {
        
        
        double d1;
        double d;
        if ([self.shu.text isEqualToString:@""]){
            
            self.shu.text =wufuhaopayAmount.text;
            
        } else {
            
            
        }
        
        
        d=[self.shu.text doubleValue];
        
        d1=[self.shu1.text doubleValue];
        
        
        if ([str isEqualToString:@"+"]) {
            
            NSString*GoldPrice=[NSString stringWithFormat:@"%.2f", d+d1];
            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
            [numberFormatter setPositiveFormat:@"###,##0.00;"];
            NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
            
            payAmount.text=[NSString stringWithFormat:@"¥ %.2f", d+d1];
            payAmount.textAlignment = NSTextAlignmentRight;
            payAmount.textColor=[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0];
            NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@" ,formattedNumberString]];
            
            [AttributedStr addAttribute:NSFontAttributeName
             
                                  value:[UIFont systemFontOfSize:25.0]
             
                                  range:NSMakeRange(0, 1)];
            
            [AttributedStr addAttribute:NSForegroundColorAttributeName
             
                                  value:[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0]
             
                                  range:NSMakeRange(0, 1)];
            
            
            payAmount.attributedText = AttributedStr;
            
            wufuhaopayAmount.text=GoldPrice;
            jiajianhao.text=GoldPrice;
        }else{
            
            
            NSString*GoldPrice=[NSString stringWithFormat:@"%.2f", d-d1];
            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
            [numberFormatter setPositiveFormat:@"###,##0.00;"];
            NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
            
            payAmount.text=[NSString stringWithFormat:@"¥ %.2f", d-d1];
            payAmount.textAlignment = NSTextAlignmentRight;
            payAmount.textColor=[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0];
            NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@" ,formattedNumberString]];
            
            [AttributedStr addAttribute:NSFontAttributeName
             
                                  value:[UIFont systemFontOfSize:25.0]
             
                                  range:NSMakeRange(0, 1)];
            
            [AttributedStr addAttribute:NSForegroundColorAttributeName
             
                                  value:[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0]
             
                                  range:NSMakeRange(0, 1)];
            
            
            payAmount.attributedText = AttributedStr;
            
            
            wufuhaopayAmount.text=GoldPrice;
            jiajianhao.text=GoldPrice;
            
        }
        
        _isUseInEnteringANumber = YES;
        _isContinue=NO;
        self.shu.text=@"";
        self.shu1.text = @"";
       
            if (sender.tag==201) {
                
                str=@"+";
                NSString *digit = sender.currentTitle;
                
                jiajianhao.text = [jiajianhao.text stringByAppendingString:digit];
                _isUseInEnteringANumber = NO;
                _isContinue=NO;
                
            }else{
                str=@"-";
                NSString *digit = sender.currentTitle;
                jiajianhao.text = [jiajianhao.text stringByAppendingString:digit];
                _isUseInEnteringANumber = NO;
                _isContinue=NO;
                
            }
    
        
        
    }else
    
    
    if ([jiajianhao.text isEqualToString:@""]) {
        
    }else{
    
    if ([str length]>0) {
            
        }else{
            if (sender.tag==201) {
                
                str=@"+";
                NSString *digit = sender.currentTitle;
                
                jiajianhao.text = [jiajianhao.text stringByAppendingString:digit];
                _isUseInEnteringANumber = NO;
                _isContinue=NO;
                
            }else{
                str=@"-";
                NSString *digit = sender.currentTitle;
                jiajianhao.text = [jiajianhao.text stringByAppendingString:digit];
                _isUseInEnteringANumber = NO;
                _isContinue=NO;
                
            }}
    
   }
    


    
    
    

    
}

- (void)qingkong:(UIButton *)sender {
    payAmount.text = @"0.00";
    self.shu.text = @"";
    self.shu1.text = @"";
    jiajianhao.text = @"";
    _isUseInEnteringANumber = YES;
    _isContinue=NO;
    str=@"";
}

- (void)dengyu:(UIButton *)sender {
    double d1;
    double d;
    if ([self.shu.text isEqualToString:@""]){
        
        self.shu.text =wufuhaopayAmount.text;
        
    } else {
        
        
    }
    
    
    d=[self.shu.text doubleValue];
    
    d1=[self.shu1.text doubleValue];
    
    
    if ([str isEqualToString:@"+"]) {
        
        NSString*GoldPrice=[NSString stringWithFormat:@"%.2f", d+d1];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
        
        payAmount.text=[NSString stringWithFormat:@"¥ %.2f", d+d1];
        payAmount.textAlignment = NSTextAlignmentRight;
        payAmount.textColor=[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0];
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@" ,formattedNumberString]];
        
        [AttributedStr addAttribute:NSFontAttributeName
         
                              value:[UIFont systemFontOfSize:25.0]
         
                              range:NSMakeRange(0, 1)];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0]
         
                              range:NSMakeRange(0, 1)];
        
        
        payAmount.attributedText = AttributedStr;

        wufuhaopayAmount.text=GoldPrice;
        jiajianhao.text=GoldPrice;
    }else{
        
       
        NSString*GoldPrice=[NSString stringWithFormat:@"%.2f", d-d1];
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
        
        payAmount.text=[NSString stringWithFormat:@"¥ %.2f", d-d1];
        payAmount.textAlignment = NSTextAlignmentRight;
        payAmount.textColor=[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0];
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@" ,formattedNumberString]];
        
        [AttributedStr addAttribute:NSFontAttributeName
         
                              value:[UIFont systemFontOfSize:25.0]
         
                              range:NSMakeRange(0, 1)];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0]
         
                              range:NSMakeRange(0, 1)];
        
        
        payAmount.attributedText = AttributedStr;

   
        wufuhaopayAmount.text=GoldPrice;
        jiajianhao.text=GoldPrice;
    
    }
    
    _isUseInEnteringANumber = YES;
     _isContinue=NO;
    self.shu.text=@"";
    self.shu1.text = @"";
//  jiajianhao.text = @"";
    str=@"";
    
   
  
    
    
}


-(void)addProduct:(UIButton*)sender{
    [View removeFromSuperview];
     commdity.orderType=@"";
    BusinessGatheringViewController *detailViewController = [[BusinessGatheringViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];

}

-(void)tianjia:(UIButton *)sender{
    
    
    [addView removeFromSuperview];
    
    
    saveAccount=! saveAccount;
    
    if (!saveAccount) {
        View=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        View.backgroundColor=[UIColor clearColor];
        [self.view addSubview:View];
        // 手势
        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad1)];
        singleFingerOne.numberOfTouchesRequired = 1; //手指数
        singleFingerOne.numberOfTapsRequired = 1; //tap次数
        singleFingerOne.delegate = self;
        [View addGestureRecognizer:singleFingerOne];
        
        
        
        addView=[[UIView alloc]initWithFrame:CGRectMake(ScreenWidth-185, 64, 170, 336/2)];
        addView.backgroundColor=[UIColor colorWithRed:40/255.0 green:65/255.0 blue:1/255.0 alpha:1.0];
        addView.alpha=0.94;
        [addView.layer setCornerRadius:3.0]; //设置矩圆角半径
        [addView.layer setBorderWidth:0.3];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){40/255.0,65/255.0, 1/255.0, 1.0});
        [addView.layer setBorderColor:tureBTncolorref];//边框颜色

        [View addSubview:addView];
        UIImage *img=[UIImage imageNamed:@"xialajiantou"];

        UIImageView*imageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-35, 64-3.5, 10, 3.5)];

        imageview.image=img;
        imageview.alpha=1;
      
        [View addSubview:imageview];
        
        
        NSArray *buttonContent = @[@"     会员",@"            未付订单",@"            历史账单"];
        NSArray *buttonContentimage = @[@"shouyin_huiyuan",@"weifudingdan",@"shouyin_lishizhangdan"];
        for (int i = 0;  i<3; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(0, 2.5+336/2/3*i, 170, 50);
            [button setTitle:[buttonContent objectAtIndex:i] forState:UIControlStateNormal];
            button.titleLabel.font=[UIFont systemFontOfSize:15];
            button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
            [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = i+1;
            button.alpha=0.88;
            [addView addSubview:button];
         
            
            UIButton *shanghubutton = [UIButton buttonWithType:UIButtonTypeCustom];
            shanghubutton.frame = CGRectMake(35, 7.5+336/2/3*i, 40, 40);
            [shanghubutton setBackgroundImage:[UIImage imageNamed:[buttonContentimage objectAtIndex:i]] forState:UIControlStateNormal];
//          [shanghubutton setImage: forState:UIControlStateNormal];
            [addView addSubview:shanghubutton];
            if (i==0) {
                
            }else{
            UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(10, 336/2/3*i, 170-20, 0.35)];
            line.backgroundColor=luseColor;
            [addView addSubview:line];
            }
           
            
        }
    }else{
        
        
        [addView removeFromSuperview];
        
    }
    
    
}
- (void)buttonAction:(UIButton *)button{
    saveAccount=YES;
    [View removeFromSuperview];
    switch (button.tag)
    {
        case 1:
            
            if (button.tag==1) {
                [NOView removeFromSuperview];
               
                commdity.orderType=@"other";
                 wufuhaopayAmount.text=@"0.00";
                 payAmount.text=@"0.00";
                commdity.addhuiyuanViewController=@"选择";
                huiyuandengjiViewController*de = [[huiyuandengjiViewController alloc] init];
                
                [self.navigationController pushViewController:de animated:YES];
                
//                [self showAlertMessage:@"待后台完善接口"];
            }
            break;
            
        case 2:
            
            if (button.tag==2) {
                [NOView removeFromSuperview];
         
                
                commdity.sat=@"tuihui";
                commdity.filterType=@"npayOrder";
                commdity.filterNPay=@"Y";
                orderListsViewController*de = [[orderListsViewController alloc] init];
                
                [self.navigationController pushViewController:de animated:YES];
                
                
            }
            
            break;
            
        case 3:
            
            if (button.tag==3) {
                [NOView removeFromSuperview];
                
                
                [View removeFromSuperview];
                commdity.orderType=@"";
                BusinessGatheringViewController *detailViewController = [[BusinessGatheringViewController alloc] init];
                [self.navigationController pushViewController:detailViewController animated:YES];
                
                
            }
            
            break;

            
        default:
            break;
    }
}



-(void)closeKeyBoad1
{
    saveAccount=YES;
    [View removeFromSuperview];
  
}


//商品收银
-(void)shouyin{

   
    
    
    
    commdity.how=[NSString stringWithFormat:@"%@",[commdity.Dict objectForKey:@"payAmount"]];
   
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",@"0.00"];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
   
    payAmount=[[UILabel alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth-15,ScreenHeight-64-ScreenWidth-60)];
    payAmount.text=[NSString stringWithFormat:@"%@", @"0.00"];
    payAmount.textAlignment = NSTextAlignmentRight;
    payAmount.font=[UIFont systemFontOfSize:daixao];
    payAmount.backgroundColor=[UIColor colorWithRed:14/255.0 green:23/255.0 blue:0/255.0 alpha:1.0];
    payAmount.textColor=[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0];
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@" ,formattedNumberString]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:30]
     
                          range:NSMakeRange(0, 1)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:[UIColor colorWithRed:225/255.0 green:238/255.0 blue:203/255.0 alpha:1.0]
     
                          range:NSMakeRange(0, 1)];
    
    
    
    [self.view addSubview:payAmount];
   
    UILabel*bianView=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-15, 64,15 ,ScreenHeight-64-ScreenWidth-60)];
    
    bianView.backgroundColor=[UIColor colorWithRed:14/255.0 green:23/255.0 blue:0/255.0 alpha:1.0];
    
    [self.view addSubview:bianView];

    
    wufuhaopayAmount=[[UILabel alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth-15,60)];
    wufuhaopayAmount.text=[NSString stringWithFormat:@"%@", @"0.00"];
    wufuhaopayAmount.textAlignment = NSTextAlignmentRight;
    wufuhaopayAmount.textColor=[UIColor clearColor];
    [self.view addSubview:wufuhaopayAmount];

    UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, 64+0.45, ScreenWidth,0.35)];
    line.backgroundColor=luseColor;
    [self.view addSubview:line];
    jiajianhao=[[UILabel alloc]initWithFrame:CGRectMake(0, payAmount.bottom-40, ScreenWidth-15,40)];
    jiajianhao.textAlignment = NSTextAlignmentRight;
    jiajianhao.textColor=luseColor;
    jiajianhao.font=[UIFont boldSystemFontOfSize:20];
    [self.view addSubview:jiajianhao];
    
    
    NSArray *array = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@".",@"0"];
   
        for (int i = 0,j = 0; i < array.count; i++) {
            if (i % 3 == 0) {
                j++;
            }
        UIButton *shanghubutton = [UIButton buttonWithType:UIButtonTypeCustom];
        shanghubutton.frame = CGRectMake(ScreenWidth/4*(i%3),payAmount.bottom-ScreenWidth/4+(ScreenWidth/4*j), ScreenWidth/4, ScreenWidth/4);
        shanghubutton.tag = 301+i;
        [shanghubutton setTitle:[array objectAtIndex:i] forState:UIControlStateNormal];
        [shanghubutton setTitleColor:shenhuicolor forState:UIControlStateNormal];
        shanghubutton.backgroundColor=zuiqianhuicolor;
        [shanghubutton addTarget:self action:@selector(shuzi:) forControlEvents:UIControlEventTouchUpInside];
        shanghubutton.layer.borderColor = LineColor.CGColor;
        [shanghubutton.layer setBorderWidth:0.55];   //边
        shanghubutton.titleLabel.font=[UIFont systemFontOfSize:24];
        [self.view addSubview:shanghubutton];
  
          
    }

    
    
    
    
    UIButton *qingkong = [UIButton buttonWithType:UIButtonTypeCustom];
    qingkong.frame = CGRectMake((ScreenWidth/4*3),payAmount.bottom-ScreenWidth/4+(ScreenWidth/4*1), ScreenWidth/4, ScreenWidth/4);
    [qingkong setTitle:@"←" forState:UIControlStateNormal];
    [qingkong setTitleColor:shenhuicolor forState:UIControlStateNormal];
    qingkong.backgroundColor=zuiqianhuicolor;
    [qingkong addTarget:self action:@selector(qingkong:) forControlEvents:UIControlEventTouchUpInside];
    qingkong.layer.borderColor = LineColor.CGColor;
    [qingkong.layer setBorderWidth:0.55];   //边
    qingkong.titleLabel.font=[UIFont systemFontOfSize:24];
    [self.view addSubview:qingkong];

    
    
    NSArray *array1 = @[@"+",@"-"];
    
    for (int i = 0; i < array1.count; i++) {
        
        UIButton *shanghubutton = [UIButton buttonWithType:UIButtonTypeCustom];
//       shanghubutton.frame = CGRectMake(ScreenWidth/2+(ScreenWidth/4*i),payAmount.bottom-ScreenWidth/4+(ScreenWidth/4*4), ScreenWidth/4, ScreenWidth/4);
        
        shanghubutton.frame = CGRectMake((ScreenWidth/4*3),qingkong.bottom+ScreenWidth/4*i, ScreenWidth/4, ScreenWidth/4);
        shanghubutton.tag = 201+i;
        [shanghubutton setTitle:[array1 objectAtIndex:i] forState:UIControlStateNormal];
        [shanghubutton setTitleColor:shenhuicolor forState:UIControlStateNormal];
        shanghubutton.backgroundColor=zuiqianhuicolor;
        [shanghubutton addTarget:self action:@selector(jiajianfa:) forControlEvents:UIControlEventTouchUpInside];
        shanghubutton.layer.borderColor = LineColor.CGColor;
        [shanghubutton.layer setBorderWidth:0.55];   //边
        shanghubutton.titleLabel.font=[UIFont systemFontOfSize:24];
        [self.view addSubview:shanghubutton];
        
        
    }

    UIButton *dengyu = [UIButton buttonWithType:UIButtonTypeCustom];
    dengyu.frame = CGRectMake(ScreenWidth/2,payAmount.bottom-ScreenWidth/4+(ScreenWidth/4*4), ScreenWidth/4*2, ScreenWidth/4);
    [dengyu setTitle:@"=" forState:UIControlStateNormal];
    [dengyu setTitleColor:shenhuicolor forState:UIControlStateNormal];
    dengyu.backgroundColor=zuiqianhuicolor;
    [dengyu addTarget:self action:@selector(dengyu:) forControlEvents:UIControlEventTouchUpInside];
    dengyu.layer.borderColor = LineColor.CGColor;
    [dengyu.layer setBorderWidth:0.55];   //边
    dengyu.titleLabel.font=[UIFont systemFontOfSize:24];
    [self.view addSubview:dengyu];
    

    
    UILabel*line1=[[UILabel alloc]initWithFrame:CGRectMake(0, ScreenHeight-60-0.45, ScreenWidth,0.45)];
    line1.backgroundColor=qianhuicolor;
    [self.view addSubview:line1];
    
    UIButton*btn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-60, ScreenWidth/4, 60)];
    btn.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    [btn addTarget:self action:@selector(xianjinlabelbtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    xianjinlabelbtn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-20, ScreenWidth/4, 13)];
    [xianjinlabelbtn  setTitle:@"现金" forState:UIControlStateNormal];
    [xianjinlabelbtn addTarget:self action:@selector(xianjinlabelbtn:) forControlEvents:UIControlEventTouchUpInside];
    [xianjinlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    xianjinlabelbtn.titleLabel .font=[UIFont systemFontOfSize:13];
    [self.view addSubview:xianjinlabelbtn];
    
    UIButton*imagebtn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-60, ScreenWidth/4, 40)];
    [imagebtn addTarget:self action:@selector(xianjinlabelbtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:imagebtn];
    UIImageView*imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 45, 45)];
    imageview.image=[UIImage imageNamed:@"xianjins"];
    imageview.center=imagebtn.center;
    [self.view addSubview:imageview];
    
    
    
    UIButton*shuakabtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4, ScreenHeight-60, ScreenWidth/4, 60)];
    shuakabtn.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    [shuakabtn addTarget:self action:@selector(shuakabtnlabelbtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shuakabtn];
    shuakabtnlabelbtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4, ScreenHeight-20, ScreenWidth/4, 13)];
    [shuakabtnlabelbtn  setTitle:@"刷卡" forState:UIControlStateNormal];
    [shuakabtnlabelbtn addTarget:self action:@selector(shuakabtnlabelbtn:) forControlEvents:UIControlEventTouchUpInside];
    [shuakabtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    shuakabtnlabelbtn.titleLabel .font=[UIFont systemFontOfSize:13];
    [self.view addSubview:shuakabtnlabelbtn];
    UIButton*shuakabtnlabelbtnimagebtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4, ScreenHeight-60, ScreenWidth/4, 40)];
    [shuakabtnlabelbtnimagebtn addTarget:self action:@selector(shuakabtnlabelbtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shuakabtnlabelbtnimagebtn];
    UIImageView*shuakabtnlabelbtnimagebtnimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/4, 0, 45, 45)];
    shuakabtnlabelbtnimagebtnimageview.image=[UIImage imageNamed:@"shuakas"];
    shuakabtnlabelbtnimagebtnimageview.center=shuakabtnlabelbtnimagebtn.center;
    [self.view addSubview:shuakabtnlabelbtnimagebtnimageview];
    
    UIButton*zhifubaobtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4*2, ScreenHeight-60, ScreenWidth/4, 60)];
    zhifubaobtn.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    [zhifubaobtn addTarget:self action:@selector(zhifubaobtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:zhifubaobtn];
    zhifulabelbaobtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4*2, ScreenHeight-20, ScreenWidth/4, 13)];
    [zhifulabelbaobtn  setTitle:@"支付宝" forState:UIControlStateNormal];
    [zhifulabelbaobtn addTarget:self action:@selector(zhifubaobtn:) forControlEvents:UIControlEventTouchUpInside];
    [zhifulabelbaobtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    zhifulabelbaobtn.titleLabel .font=[UIFont systemFontOfSize:13];
    [self.view addSubview:zhifulabelbaobtn];
    UIButton*zhifubaobtn1imagebtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4*2, ScreenHeight-60, ScreenWidth/4, 40)];
    [zhifubaobtn1imagebtn addTarget:self action:@selector(zhifubaobtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:zhifubaobtn1imagebtn];
    UIImageView*zhifubaobtnimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/4*2, 0, 45, 45)];
    zhifubaobtnimageview.image=[UIImage imageNamed:@"zhifubaos"];
    zhifubaobtnimageview.center=zhifubaobtn1imagebtn.center;
    [self.view addSubview:zhifubaobtnimageview];
    
    
    
    UIButton*weixinbtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4*3, ScreenHeight-60, ScreenWidth/4, 60)];
    weixinbtn.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    [weixinbtn addTarget:self action:@selector(weixinbtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:weixinbtn];
    weixinbtnlabelbtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4*3, ScreenHeight-20, ScreenWidth/4, 13)];
    [weixinbtnlabelbtn  setTitle:@"微信" forState:UIControlStateNormal];
    [weixinbtnlabelbtn addTarget:self action:@selector(weixinbtn:) forControlEvents:UIControlEventTouchUpInside];
    [weixinbtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    weixinbtnlabelbtn.titleLabel .font=[UIFont systemFontOfSize:13];
    [self.view addSubview:weixinbtnlabelbtn];
    
    UIButton*weixinbtnlabelbtnimagebtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/4*3, ScreenHeight-60, ScreenWidth/4, 40)];
    [weixinbtnlabelbtnimagebtn addTarget:self action:@selector(weixinbtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:weixinbtnlabelbtnimagebtn];
    UIImageView*weixinbtnlabelbtnimagebtnimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/4*3, 0, 45, 45)];
    weixinbtnlabelbtnimagebtnimageview.image=[UIImage imageNamed:@"weixins"];
    weixinbtnlabelbtnimagebtnimageview.center=weixinbtnlabelbtnimagebtn.center;
    [self.view addSubview:weixinbtnlabelbtnimagebtnimageview];
    
    
    
}



- (void)xianjinlabelbtn:(UIButton *)button{
    [myscrollView removeFromSuperview];
    [ditu removeFromSuperview];
      [chaimageview removeFromSuperview];
      [chaimageview removeFromSuperview];
    if ([wufuhaopayAmount.text isEqualToString:@"0.00"]) {
        [self showAlertMessage:@"收款金额不能为0"];
    }else{
        
        if ([payAmount.text isEqualToString:@"0.00"]) {
            [self showAlertMessage:@"收款金额不能为0"];
        }else{
    [shoukuanfangsi removeFromSuperview];
    payType=@"C";
    [xianjinlabelbtn setTitleColor:shenluse forState:UIControlStateNormal];
    [shuakabtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [zhifulabelbaobtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [weixinbtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [self add];
    }
    }
}

- (void)shuakabtnlabelbtn:(UIButton *)button{
       [self showAlertMessage:@"未开通！"];
//    [shoukuanfangsi removeFromSuperview];
//    payType=@"B";
//    [xianjinlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    [shuakabtnlabelbtn setTitleColor:shenluse forState:UIControlStateNormal];
//    [zhifulabelbaobtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    [weixinbtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    [self add];
    
    
}
- (void)zhifubaobtn:(UIButton *)button{

       if ([wufuhaopayAmount.text isEqualToString:@"0.00"]) {
        [self showAlertMessage:@"收款金额不能为0"];
    }else{
        
        if ([payAmount.text isEqualToString:@"0.00"]) {
            [self showAlertMessage:@"收款金额不能为0"];
        }else{
            
            
            [myscrollView removeFromSuperview];
            [ditu removeFromSuperview];
            [chaimageview removeFromSuperview];
            [shoukuanfangsi removeFromSuperview];
            [xianjinlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            [shuakabtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            [zhifulabelbaobtn setTitleColor:shenluse forState:UIControlStateNormal];
            [weixinbtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
            
            
            [myscrollView removeFromSuperview];
            ditu=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight+60)];
            ditu.backgroundColor=backColor;
            ditu.alpha=0.6;
            [self.view addSubview:ditu];
            //     手势
            UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
            singleFingerOne.numberOfTouchesRequired = 1; //手指数
            singleFingerOne.numberOfTapsRequired = 1; //tap次数
            singleFingerOne.delegate = self;
            [ditu addGestureRecognizer:singleFingerOne];
            
            
            myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,payAmount.bottom-0.5, ScreenWidth, ScreenWidth)];
            [myscrollView setBackgroundColor: [UIColor whiteColor]];
            
            myscrollView.delegate = self;
            myscrollView.userInteractionEnabled = YES;
            myscrollView.scrollEnabled = YES;
            myscrollView.showsVerticalScrollIndicator = FALSE;
            myscrollView.showsHorizontalScrollIndicator = FALSE;
            [self.view addSubview:myscrollView];
            
            
            
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            NSMutableDictionary *params = [NSMutableDictionary new];
            [params setValue:Token forKey:@"tokenId"];
//            [params setValue:@"other" forKey:@"orderType"];
            [params setValue:commdity.orderType forKey:@"orderType"];
            [params setValue:commdity.orderId  forKey:@"orderId"];
            [params setValue:commdity.memberId forKey:@"memberId"];
            [params setValue:commdity.userName  forKey:@"memberName"];

            [params setValue:[NSString stringWithFormat:@"%.2f",  [wufuhaopayAmount.text doubleValue]] forKey:@"payAmount"];
            
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            NSLog(@"--------%@",params);
            
            [HttpRequest requestData:@"Business/Pay/AliQrPay" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    
                    NSLog(@"%@",severDataDict.dataDict);
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        
                        [Global hideProgressHUDInternal:self.view];
                        commdity.gid=[severDataDict.dataDict objectForKey:@"gid"];
                        [self times];
                        NSString*s=@"支付宝支付";
                        
                         [self str:s priceStr:payAmount.text QRStr:[severDataDict.dataDict  objectForKey:@"qrCode"]];
                        
                        
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSLog(@"aaaaaaaa%@",severDataDict.dataDict);
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
        }
        chaimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-50, payAmount.bottom-15, 30, 30)];
        chaimageview .image=[UIImage imageNamed:@"chas"];
        //    [chaimageview addGestureRecognizer:singleFingerOne];
        [self.view addSubview:chaimageview];
    }

    
}
//微信支付
- (void)weixinbtn:(UIButton *)button{
    
      [chaimageview removeFromSuperview];
    if ([wufuhaopayAmount.text isEqualToString:@"0.00"]) {
        [self showAlertMessage:@"收款金额不能为0"];
    }else{
        
        if ([payAmount.text isEqualToString:@"0.00"]) {
            [self showAlertMessage:@"收款金额不能为0"];
        }else{


    [myscrollView removeFromSuperview];
    [ditu removeFromSuperview];
    [chaimageview removeFromSuperview];
    [shoukuanfangsi removeFromSuperview];
    [xianjinlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [shuakabtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [zhifulabelbaobtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [weixinbtnlabelbtn setTitleColor:shenluse forState:UIControlStateNormal];
    
    
    [myscrollView removeFromSuperview];
    ditu=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight+60)];
    ditu.backgroundColor=backColor;
    ditu.alpha=0.6;
    [self.view addSubview:ditu];
    //     手势
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [ditu addGestureRecognizer:singleFingerOne];
    
    
    myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,payAmount.bottom-0.5, ScreenWidth, ScreenWidth)];
    [myscrollView setBackgroundColor: [UIColor whiteColor]];
    
    myscrollView.delegate = self;
    myscrollView.userInteractionEnabled = YES;
    myscrollView.scrollEnabled = YES;
    myscrollView.showsVerticalScrollIndicator = FALSE;
    myscrollView.showsHorizontalScrollIndicator = FALSE;
    [self.view addSubview:myscrollView];
    
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setValue:Token forKey:@"tokenId"];
//    [params setValue:@"other" forKey:@"orderType"];
    [params setValue:commdity.orderType forKey:@"orderType"];
    [params setValue:commdity.orderId  forKey:@"orderId"];
    [params setValue:commdity.memberId forKey:@"memberId"];
    [params setValue:commdity.userName  forKey:@"memberName"];
    [params setValue:[NSString stringWithFormat:@"%.2f",  [wufuhaopayAmount.text doubleValue]] forKey:@"payAmount"];
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    NSLog(@"--------%@",params);
    
    [HttpRequest requestData:@"Business/Pay/WxScanPay" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                
                [Global hideProgressHUDInternal:self.view];
                commdity.gid=[severDataDict.dataDict objectForKey:@"gid"];
                [self times];
               
                NSString*s=@"微信支付";
                
                [self str:s priceStr:payAmount.text QRStr:[severDataDict.dataDict  objectForKey:@"qrCode"]];
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            NSLog(@"aaaaaaaa%@",severDataDict.dataDict);
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    }
    chaimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-50, payAmount.bottom-15, 30, 30)];
    chaimageview .image=[UIImage imageNamed:@"chas"];
    //    [chaimageview addGestureRecognizer:singleFingerOne];
    [self.view addSubview:chaimageview];
}
}

-(void)str:(NSString*)strs priceStr:(NSString*)priceStr QRStr:(NSString*)QRStr{

    
    NSString *s12 = [NSString stringWithFormat:@"%@",  @"你选择"];
    UIFont *font12 = [UIFont systemFontOfSize:15];
    CGSize size12 = CGSizeMake(320, 2000);
    CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];

    
    UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2-100, 27, labelsize12.width, 15)];
    label1.text=[NSString stringWithFormat:@"%@",@"你选择"];
    label1.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    label1.font=[UIFont systemFontOfSize:15];
    [myscrollView addSubview:label1];
    
    NSString *s1 = [NSString stringWithFormat:@"%@",  strs];
    UIFont *font1= [UIFont systemFontOfSize:15];
    CGSize size1= CGSizeMake(320, 2000);
    CGSize labelsize1= [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
    UILabel*label2=[[UILabel alloc]initWithFrame:CGRectMake(label1.right+5, 27, labelsize1.width+10, 15)];
    label2.text=[NSString stringWithFormat:@"%@",strs];
    label2.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
    label2.textColor=[UIColor whiteColor];
    label2.textAlignment=NSTextAlignmentCenter;
    label2.font=[UIFont systemFontOfSize:14];
    [myscrollView addSubview:label2];
    UILabel*label3=[[UILabel alloc]initWithFrame:CGRectMake(label2.right+5, 27, 100, 15)];
    label3.text=[NSString stringWithFormat:@"%@",@"需付金额:"];
    label3.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    label3.font=[UIFont systemFontOfSize:15];
    [myscrollView addSubview:label3];
    

    UILabel*payAmounts=[[UILabel alloc]initWithFrame:CGRectMake(0, label1.bottom+7.5, ScreenWidth, 24)];
    payAmounts.text=[NSString stringWithFormat:@"%@",payAmount.text];
    payAmounts.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    payAmounts.textAlignment=NSTextAlignmentCenter;
    payAmounts.font=[UIFont systemFontOfSize:24];
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",payAmount.text]];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:[UIFont systemFontOfSize:14]
     
                          range:NSMakeRange(0, 1)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]
     
                          range:NSMakeRange(0, 1)];
    payAmounts.attributedText = AttributedStr;
    
    [myscrollView addSubview:payAmounts];
    

    
    Btnture = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-75, payAmounts.bottom+132/2, 150, 150)];
    [Btnture setImageWithURL:[NSURL URLWithString:QRStr]];
    Btnture.contentMode = UIViewContentModeScaleAspectFit;
    [myscrollView addSubview:Btnture];
    
    
    [myscrollView setContentSize:CGSizeMake(ScreenWidth, Btnture.bottom+60)];

}







- (void)times{
    
    time = [[UIButton alloc]init];
    time.frame = CGRectMake(ScreenWidth-100,ScreenHeight*35/2200,30,16);
    [time setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    [time setTitle:[NSString stringWithFormat:@"%d",10] forState:UIControlStateNormal];
    time.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [myscrollView addSubview:time];
    
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDownActions:) userInfo:time repeats:YES];
    
    
}
//自动更新
-(void)countDownActions:(NSTimer*)timer{
    
    time = timer.userInfo;
    
    if (!time.superview) {
        [timer invalidate];
        return;
    }
    int currentTime = [[time titleForState:UIControlStateNormal] intValue];
    [time setTitle:[NSString stringWithFormat:@"%d",--currentTime] forState:UIControlStateNormal];
    time.titleLabel.font = [UIFont systemFontOfSize:16];
    if (currentTime<1) {
        
        [time setTitle:[NSString stringWithFormat:@"%d",10] forState:UIControlStateNormal];
        [self times];
        [time removeFromSuperview];
        
        
        
        
            
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            NSMutableDictionary *params = [NSMutableDictionary new];
            [params setValue:Token forKey:@"tokenId"];
            [params setValue:commdity.gid forKey:@"gid"];
            NSLog(@"%@",params);
            
            [HttpRequest requestData:@"Business/Gathering/Detail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        
                        if ([[NSString stringWithFormat:@"%@",   [severDataDict.dataDict  objectForKey:@"status"]] isEqualToString:@"N"]) {
                            
                        }if ([[NSString stringWithFormat:@"%@",   [severDataDict.dataDict  objectForKey:@"status"]] isEqualToString:@"Y"]) {
                            
                            [time setTitle:[NSString stringWithFormat:@"%d",10000000] forState:UIControlStateNormal];
                            
                            [timer invalidate];
                            
                            [myscrollView removeFromSuperview];
                            [ditu removeFromSuperview];
                            [chaimageview removeFromSuperview];
                            [View removeFromSuperview];
                            [NOView removeFromSuperview];
                            self.shu.text = @"";
                            wufuhaopayAmount.text=@"0.00";
                            payAmount.text=@"0.00";
                            jiajianhao.text=@"0.00";
                           commdity.orderType=@"";
                            BusinessGatheringDetailViewController *detailViewController = [[BusinessGatheringDetailViewController alloc] init];
                            [self.navigationController pushViewController:detailViewController animated:YES];
                           
                            
                            
                        }
                        
                        
                    }else{
                        
                        
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSLog(@"aaaaaaaa%@",severDataDict.dataDict);
                    [timer invalidate];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
        
    }
    
    
    
}

//现金支付//刷卡支付


-(void)add{
    [myscrollView removeFromSuperview];
    [chaimageview removeFromSuperview];
    ditu=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight+60)];
    ditu.backgroundColor=backColor;
    ditu.alpha=0.6;
    [self.view addSubview:ditu];
//  手势
    
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [ditu addGestureRecognizer:singleFingerOne];

    
    myscrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,payAmount.bottom-0.5, ScreenWidth, ScreenWidth)];
    [myscrollView setBackgroundColor: [UIColor whiteColor]];
    
    myscrollView.delegate = self;
    myscrollView.userInteractionEnabled = YES;
    myscrollView.scrollEnabled = YES;
    myscrollView.showsVerticalScrollIndicator = FALSE;
    myscrollView.showsHorizontalScrollIndicator = FALSE;
    [self.view addSubview:myscrollView];
    
    
    
    if ([payType isEqualToString:@"C"]) {
        NSString*strs=@"现金支付";
       
        NSString *s12 = [NSString stringWithFormat:@"%@",  @"你选择"];
        UIFont *font12 = [UIFont systemFontOfSize:15];
        CGSize size12 = CGSizeMake(320, 2000);
        CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
        
        
        UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2-100, height5or6, labelsize12.width, 15)];
        label1.text=[NSString stringWithFormat:@"%@",@"你选择"];
        label1.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
        label1.font=[UIFont systemFontOfSize:15];
        [myscrollView addSubview:label1];
        
        NSString *s1 = [NSString stringWithFormat:@"%@",  strs];
        UIFont *font1= [UIFont systemFontOfSize:15];
        CGSize size1= CGSizeMake(320, 2000);
        CGSize labelsize1= [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
        UILabel*label2=[[UILabel alloc]initWithFrame:CGRectMake(label1.right+5, height5or6, labelsize1.width+10, 15)];
        label2.text=[NSString stringWithFormat:@"%@",strs];
        label2.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
        label2.textColor=[UIColor whiteColor];
        label2.textAlignment=NSTextAlignmentCenter;
        label2.font=[UIFont systemFontOfSize:14];
        [myscrollView addSubview:label2];
        UILabel*label3=[[UILabel alloc]initWithFrame:CGRectMake(label2.right+5, height5or6, 100, 15)];
        label3.text=[NSString stringWithFormat:@"%@",@"需付金额:"];
        label3.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
        label3.font=[UIFont systemFontOfSize:15];
        [myscrollView addSubview:label3];

        
        UILabel*payAmounts=[[UILabel alloc]initWithFrame:CGRectMake(0, label1.bottom+7.5, ScreenWidth, 24)];
        payAmounts.text=[NSString stringWithFormat:@"%@",payAmount.text];
        payAmounts.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
        payAmounts.textAlignment=NSTextAlignmentCenter;
        payAmounts.font=[UIFont systemFontOfSize:24];
        
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",payAmount.text]];
        
        [AttributedStr addAttribute:NSFontAttributeName
         
                              value:[UIFont systemFontOfSize:14]
         
                              range:NSMakeRange(0, 1)];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]
         
                              range:NSMakeRange(0, 1)];
        payAmounts.attributedText = AttributedStr;
        
        [myscrollView addSubview:payAmounts];
        Btnture = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-50, payAmounts.bottom+75, 215/2,  215/2)];
        Btnture.layer.masksToBounds = YES;
        Btnture.backgroundColor=luseColor ;
        Btnture.layer.cornerRadius =  215/2/2;
        [Btnture setTitle:@"确定" forState:UIControlStateNormal];
        [Btnture setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [Btnture addTarget:self action:@selector(ture:) forControlEvents:UIControlEventTouchUpInside];
        Btnture.layer.borderColor = [UIColor whiteColor].CGColor;
        Btnture.layer.borderWidth = 0;
        Btnture.contentMode = UIViewContentModeScaleAspectFit;
        Btnture.titleLabel.font=[UIFont systemFontOfSize:18];
        [myscrollView addSubview:Btnture];
        
    }
    if ([payType isEqualToString:@"B"]) {
        NSString*strs=@"刷卡支付";
        
       
        NSString *s12 = [NSString stringWithFormat:@"%@",  @"你选择"];
        UIFont *font12 = [UIFont systemFontOfSize:15];
        CGSize size12 = CGSizeMake(320, 2000);
        CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
        
        
        UILabel*label1=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2-100, height5or6, labelsize12.width, 15)];
        label1.text=[NSString stringWithFormat:@"%@",@"你选择"];
        label1.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
        label1.font=[UIFont systemFontOfSize:15];
        [myscrollView addSubview:label1];
        
        NSString *s1 = [NSString stringWithFormat:@"%@",  strs];
        UIFont *font1= [UIFont systemFontOfSize:15];
        CGSize size1= CGSizeMake(320, 2000);
        CGSize labelsize1= [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
        UILabel*label2=[[UILabel alloc]initWithFrame:CGRectMake(label1.right+5, height5or6, labelsize1.width+10, 15)];
        label2.text=[NSString stringWithFormat:@"%@",strs];
        label2.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
        label2.textColor=[UIColor whiteColor];
        label2.textAlignment=NSTextAlignmentCenter;
        label2.font=[UIFont systemFontOfSize:14];
        [myscrollView addSubview:label2];
        UILabel*label3=[[UILabel alloc]initWithFrame:CGRectMake(label2.right+5, height5or6, 100, 15)];
        label3.text=[NSString stringWithFormat:@"%@",@"需付金额:"];
        label3.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
        label3.font=[UIFont systemFontOfSize:15];
        [myscrollView addSubview:label3];
        
        
        UILabel*payAmounts=[[UILabel alloc]initWithFrame:CGRectMake(0, label1.bottom+7.5, ScreenWidth, 24)];
        payAmounts.text=[NSString stringWithFormat:@"%@",payAmount.text];
        payAmounts.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
        payAmounts.textAlignment=NSTextAlignmentCenter;
        payAmounts.font=[UIFont systemFontOfSize:24];
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",payAmount.text]];
        
        [AttributedStr addAttribute:NSFontAttributeName
         
                              value:[UIFont systemFontOfSize:14]
         
                              range:NSMakeRange(0, 1)];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]
         
                              range:NSMakeRange(0, 1)];
        payAmounts.attributedText = AttributedStr;
        
        [myscrollView addSubview:payAmounts];
        Btnture = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-50, payAmounts.bottom+75, 215/2,  215/2)];
        Btnture.layer.masksToBounds = YES;
        Btnture.backgroundColor= luseColor;
        Btnture.layer.cornerRadius =  215/2/2;
        [Btnture setTitle:@"确定" forState:UIControlStateNormal];
        [Btnture setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [Btnture addTarget:self action:@selector(ture:) forControlEvents:UIControlEventTouchUpInside];
        Btnture.layer.borderColor = [UIColor whiteColor].CGColor;
        Btnture.layer.borderWidth = 0;
        Btnture.contentMode = UIViewContentModeScaleAspectFit;
        Btnture.titleLabel.font=[UIFont systemFontOfSize:18];
        [myscrollView addSubview:Btnture];
    }
    
    
   
    
    
    
  
    
    
    [myscrollView setContentSize:CGSizeMake(ScreenWidth, Btnture.bottom+60)];
    
    chaimageview=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-50, payAmount.bottom-15, 30, 30)];
    chaimageview .image=[UIImage imageNamed:@"chas"];
//    [chaimageview addGestureRecognizer:singleFingerOne];
    [self.view addSubview:chaimageview];
}

- (void)ture:(UIButton *)button{
    
//    if ([commdity.sat isEqualToString:@"fuwushouyin"]) {
//        if ([payType length] <1)
//        {
//            [self showAlertMessage:@"请选择支付方式"];
//        }
//        else{
    
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            if (Token ==nil) {
                Token=@"dd";
            }
            
            NSMutableDictionary *params = [NSMutableDictionary new];
            [params setValue:Token forKey:@"tokenId"];
//            [params setValue:commdity.orderId forKey:@"serviceId"];
    [params setValue:commdity.orderType forKey:@"orderType"];
    [params setValue:commdity.orderId  forKey:@"orderId"];
    [params setValue:commdity.memberId forKey:@"memberId"];
    [params setValue:commdity.userName  forKey:@"memberName"];
            [params setValue:[NSString stringWithFormat:@"%.2f",  [wufuhaopayAmount.text doubleValue]] forKey:@"payAmount"];
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
            
            
            [HttpRequest requestData:@"Business/Pay/CashPay" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    NSLog(@"33333333====%@",severDataDict.dataDict);
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];

                        [self showAlertMessage:@"收银成功！"];
                        wufuhaopayAmount.text=@"0.00";
                        payAmount.text=@"0.00";
                        jiajianhao.text=@"0.00";
                        self.shu.text = @"";
                        [View removeFromSuperview];
                        [NOView removeFromSuperview];
                        [self closeKeyBoad];
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        // [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
//        }
//        
//    }
}
-(void)closeKeyBoad
{
    
     [weixinbtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
     [zhifulabelbaobtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
     [shuakabtnlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
     [xianjinlabelbtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [myscrollView removeFromSuperview];
    [ditu removeFromSuperview];
    [chaimageview removeFromSuperview];
    [time removeFromSuperview];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
